﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using Sharp.DataTransferObject;
using Sharp.Infrastructure;
using Sharp.Infrastructure.Interfaces;
using Sharp.Infrastructure.Search;

#endregion

namespace Sharp.ServiceContracts
{
    /// <summary>
    ///     表示与“用户”相关的应用层服务契约。
    /// </summary>
    [ServiceContract]
    public partial interface IUserService : IApplicationServiceContract
    {
        /// <summary>
        ///     根据指定的用户信息，创建用户对象。
        /// </summary>
        /// <param name="user">包含了用户信息的数据传输对象。</param>
        /// <returns>已创建用户对象的全局唯一标识。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result CreateUser(UserDTO user);

        /// <summary>
        ///     根据指定的用户信息，更新用户对象。
        /// </summary>
        /// <param name="user">需要更新的用户对象。</param>
        /// <returns>已更新的用户对象。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result UpdateUser(UserDTO user);
        /// <summary>
        ///     根据指定的用户信息，创建用户对象。
        /// </summary>
        /// <param name="user">包含了用户信息的数据传输对象。</param>
        /// <returns>已创建用户对象的全局唯一标识。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result SaveUser(UserDTO user);
        /// <summary>
        ///     删除用户。
        /// </summary>
        /// <param name="userids">需要删除的用户的Id。</param>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result DeleteUsers(IList<Guid> userids);
        /// <summary>
        ///     校验指定的用户用户名与密码是否一致。
        /// </summary>
        /// <param name="userName">用户用户名。</param>
        /// <param name="password">用户密码。</param>
        /// <returns>如果校验成功，则返回true，否则返回false。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        bool ValidateUser(string userName, string password);

        /// <summary>
        ///     禁用指定用户。
        /// </summary>
        /// <param name="user">需要禁用的用户。</param>
        /// <returns>如果成功，则返回true，否则返回false。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        bool DisableUser(UserDTO user);
        /// <summary>
        /// 解锁用户
        /// </summary>
        /// <param name="userName"></param>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        bool UnlockUser(string userName);

        /// <summary>
        ///     启用指定用户。
        /// </summary>
        /// <param name="user">需要启用的用户。</param>
        /// <returns>如果成功，则返回true，否则返回false。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        bool EnableUser(UserDTO user);



        /// <summary>
        ///     根据用户的全局唯一标识获取用户信息。
        /// </summary>
        /// <param name="id">用户的全局唯一标识。</param>
        /// <returns>包含了用户信息的数据传输对象。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result<UserDTO> GetUserByKey(Guid id);

        /// <summary>
        ///     根据用户的电子邮件地址获取用户信息。
        /// </summary>
        /// <param name="email">用户的电子邮件地址。</param>
        /// <returns>包含了用户信息的数据传输对象。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result<UserDTO> GetUserByEmail(string email);

        /// <summary>
        ///     根据用户的用户名获取用户信息。
        /// </summary>
        /// <param name="userName">用户的用户名。</param>
        /// <returns>包含了用户信息的数据传输对象。</returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result<UserDTO> GetUserByName(string userName);

        /// <summary>
        ///     获取分页信息
        /// </summary>
        /// <param name="pf"></param>
        /// <param name="userGroupId"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        PagedResult<UserDTO> GetUsersPaged(PagingFeature pf, Guid? userGroupId);


        /// <summary>
        ///     将指定的用户赋予指定的角色。
        /// </summary>
        /// <param name="userId">需要赋予角色的用户ID值。</param>
        /// <param name="roleId">需要向用户赋予的角色ID值。</param>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        void AssignRole(Guid userId, Guid roleId);

        /// <summary>
        ///     将指定的用户从角色中移除。
        /// </summary>
        /// <param name="userId">用户ID值。</param>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        void UnassignRole(Guid userId);

        /// <summary>
        ///     获取用户的权限
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        IEnumerable<PermissionDTO> GetPermissionByUserName(string username);

        /// <summary>
        ///     更改
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="oldPassword">旧密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        bool ChangePassword(string username, string oldPassword, string newPassword);

        [OperationContract]
        [FaultContract(typeof(FaultData))]
        bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion,
            string newPasswordAnswer);

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userDTO"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result<UserDTO> TryLogin(UserDTO userDTO);


        /// <summary>
        /// 保存用户日志
        /// </summary>
        /// <param name="log"></param>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        void SaveLog(string log);
        /// <summary>
        /// 获取用户日志
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        UserLogDTO GetUserLogInfo(Guid id);
        /// <summary>
        /// 删除用户日志
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        Result DeleteUserLogs(Guid[] ids);
        /// <summary>
        ///     获取分页信息
        /// </summary>
        /// <param name="pf"></param> 
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(FaultData))]
        PagedResult<UserLogDTO> GetUserLogPaged(PagingFeature pf);
        /// <summary>
        /// 关联用户到用户组
        /// </summary>
        /// <param name="userGroupId">用户组Id</param>
        /// <param name="userIds">用户Id</param>
        /// <returns></returns>
        Result RelationUser(Guid userGroupId, Guid[] userIds);

        /// <summary>
        /// 反关联用户组的用户
        /// </summary>
        /// <param name="userGroupId">用户组Id</param>
        /// <param name="userIds">用户Id</param>
        /// <returns></returns>
        Result UnRelationUser(Guid userGroupId, Guid[] userIds);

        
    }
}